package jiekou;

import java.util.Arrays;
import java.util.Scanner;
class PersonSortable implements Comparable<PersonSortable> 
{
	private String name;
	private int age;
	public PersonSortable(String name, int age) 
	{
		this.name = name;
		this.age = age;
	}
	public String toString() 
	{
		return name + "-" + age;
	}
	@Override
	public int compareTo(PersonSortable p) 
	{
		if (name.compareTo(p.name) == 0) 
		{
			return age - p.age;
		} 
		else 
		{
			return name.compareTo(p.name);
		}
	}
}

public class Main 
{
	public void main(String[] args) 
	{
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		PersonSortable[] p = new PersonSortable[n];
		for (int i = 0; i < n; i++) 
		{
			p[i] = new PersonSortable(in.nextLine(), in.nextInt());
		}
		Arrays.sort(p);
		for (int i = 0; i < n; i++) 
		{
			System.out.println(p[i]);
		}
		System.out.println(Arrays.toString(PersonSortable.class.getInterfaces()));
	}
}
